import 'package:flutter/material.dart';

/**
 * @author hanson
 * @version[创立日期，2023/9/9 14:41]
 * @function[功用简介 ]
 **/
class testPage extends StatefulWidget {
  const testPage({Key? key}) : super(key: key);

  @override
  _testPageState createState() => _testPageState();
}

class _testPageState extends State<testPage> {
  @override
  Widget build(BuildContext context) {

    return Scaffold(
        appBar: AppBar(
          title: Text("test"),
        ),
        body: Center(
          child: Column(
              children:[
                Container(
                  width: double.infinity,// 容器屏幕宽
                  height: 100, // 容器屏幕高
                  color: Colors.yellow,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container( //子容器1
                        width: 100,
                        color: Colors.red,
                        child: Text('子容器1'),

                      ),
                      Container( //子容器2
                        width: double.infinity,
                        color: Colors.blueGrey,
                        child: Text('子容器2'),
                      ),
                    ],
                  ),

                ),
                Container(
                  child: Column(
                      children: _getDate(),
                    )

                ),
              ]
          ),
        ) // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  List<Widget> _getDate() {
    var tempList = listData.map((e) {
      return ListTile(
        leading: Image.network((e)["imageUrl"]),
        title: Text(e["title"]),
        subtitle: Text(e["author"]),
        trailing: Icon(Icons.phone),
      );
    }
      // (e) => ListTile(
      //   title: Text(e["title"]),
      // ),
    );
    return tempList.toList();
  }


//使用ListView.builder实现：
  Widget _getListData(context, index) {
    return ListTile(
      leading: Image.network(listData[index]["imageUrl"]), // 显示在title之前
      title: Text(listData[index]['title']),
      subtitle: Text(listData[index]["author"]),
      //        显示在title之后
      trailing: Icon(Icons.phone),
      //再加子集
    );
  }
}



List listData=[
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/1.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/2.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/3.png",
  },
  {
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/4.png",
  },{
    "title":"Candy Shop",
    "author":"Mohamed Chahin",
    "imageUrl":"https://www.itying.com/images/flutter/5.png",
  }
];

